package team.future.joke.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import team.future.joke.entity.JokeLog;
import team.future.joke.param.JokeParam;
import team.future.joke.service.JokeLogService;
import team.future.joke.service.JokeService;

/**
 * Title: JokeController.java<br>
 * Description: <br>
 * Copyright (c) 未来工作室版权所有 2015    <br>
 * Create DateTime: 2015年9月2日 下午12:30:58 <br>
 * @author futurezhu
*/
@Controller
public class JokeController {

	@Autowired
	private JokeService jokeService;
	@Autowired
	private JokeLogService jokeLogService;

	@RequestMapping("/joke/list")
	@ResponseBody
	public String jokeList(@ModelAttribute("JokeParam") JokeParam param) {
		return "jcb("+JSONArray.toJSONString(jokeService.getJokeListPage(param)).toString()+")";
	}

	@RequestMapping("/joke/detail")
	@ResponseBody
	public String jokeDetail(@RequestParam("jokeId") String jokeId, @RequestParam("uid") String uid) {
		return "jcb(" + JSONArray.toJSONString(jokeService.getJoke(jokeId, uid)).toString() + ")";
	}

	@RequestMapping("/joke/log")
	@ResponseBody
	public String jokeLog(@ModelAttribute("jokeLog") JokeLog jokeLog) {
		jokeLogService.doInsertLog(jokeLog);
		JSONObject json = new JSONObject();
		json.put("success", true);
		return json.toString();
	}

}
